<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%--
  Created by IntelliJ IDEA.
  User: 周超
  Date: 2019/1/22
  Time: 18:02
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>新增商品</title>
    <script language="javascript" type="text/javascript" src="My97DatePicker/WdatePicker.js"></script>
</head>
<body>
<form id="myform" class="layui-form" action="/AddGoodsSubmitServlet" method="post">
    <input id="goId" name="goId" type="hidden" value="">
    <table>
        <tr><td>商品名称</td><td><input id="goname" name="goname" type="text" value=""/></td></tr><br>
        <tr><td>商品销量</td><td><input id="volume" name="volume" type="text" value=""/></td></tr><br>
        <tr><td>商品评价</td><td><input id="praise" name="praise" type="text" value=""/></td></tr><br>
        <tr><td>上架时间</td><td><input id="uptime" name="uptime" type="text" value="" onClick="WdatePicker({el:this,dateFmt:'yyyy-MM-dd HH:mm:ss'})"/></td></tr><br>
        <tr><td>图片地址</td><td><input id="url" name="url" type="text" value=""/></td></tr><br>
        <tr><td>商品描述</td><td><input id="describe" name="describe" class="Wdate" type="text" value="" /></td></tr><br>
        <tr><td>商品成本</td><td><input id="cost" name="cost" type="text" value=""/></td></tr><br>
        <tr><td>商品价格</td><td><input id="price" name="price" type="text" value=""/></td></tr><br>
        <tr><td>商品库存</td><td><input id="stock" name="stock" type="text" value=""/></td></tr><br>
        <tr><td>商品状态</td><td><input id="state" name="state" type="text" value=""/></td></tr><br>
        <tr>
            <td>所属分类</td>
            <td>
                <select id="goodsClass" name="goodsClass">
                    <c:forEach var="goodsClass" items="${List}">
                        <option value="${goodsClass.clId}" <c:if test="${Goods.clId==goodsClass.clId}">selected="selected"</c:if> >${goodsClass.clName}</option>
                    </c:forEach>
                </select>
            </td>
        </tr><br>
        <tr><td>商品是否参与秒杀</td><td><input id="goSecKill" name="goSecKill" type="text" value="${Goods.goSecKill}"/></td></tr><br>
        <tr><td><input id="reset" name="reset" type="reset" value="重置" /></td>
            <td>
                <input  name="sub" type="button" value="提交"  onclick="so()"/>
            </td>
            <td>
                <input  name="sub" type="button" value="取消"  onclick="undo()"/>
            </td>
        </tr><br>
    </table>
</form>
</body>
<script type="text/javascript">
    function so() {
        var goname = document.getElementById("goname").value;
        var volume = document.getElementById("volume").value;
        var praise = document.getElementById("praise").value;
        var uptime = document.getElementById("uptime").value;
        var url = document.getElementById("url").value;
        var describe = document.getElementById("describe").value;
        var cost = document.getElementById("cost").value;
        var price = document.getElementById("price").value;
        var stock = document.getElementById("stock").value;
        var state = document.getElementById("state").value;
        var goSecKill = document.getElementById("goSecKill").value;

        if (null == goname||""==goname) {
            alert("商品名称不能为空！");
            return false;
        }
        if (null == volume||""==volume) {
            alert("商品销量不能为空！");
            return false;
        }
        if (null == praise||""==praise) {
            alert("商品评价不能为空！");
            return false;
        }
        if (null == uptime||""==uptime) {
            alert("商品上架时间不能为空！");
            return false;
        }
        if (null == url||""==url) {
            alert("商品图片地址不能为空！");
            return false;
        }
        if (null == describe||""==describe) {
            alert("商品描述不能为空！");
            return false;
        }
        if (null == cost||""==cost) {
            alert("商品成本不能为空！");
            return false;
        }
        if (null == price||""==price) {
            alert("商品价格不能为空！");
            return false;
        }
        if (null == stock||""==stock) {
            alert("商品库存不能为空！");
            return false;
        }
        if (null == state||""==state) {
            alert("商品状态不能为空！");
            return false;
        }
        else if(state!=1&state!=0){
            alert("商品状态只能为0或者1！");
            return false;
        }
        if (null == goSecKill||""==goSecKill) {
            alert("商品是否参与秒杀不能为空！");
            return false;
        }
        else if(goSecKill!=1&goSecKill!=0){
            alert("商品是否参与秒杀只能为0或者1！");
            return false;
        }

        document.getElementById("myform").submit();
    }
    function undo() {
        window.location.href="GoodsPageBeanListServlet";
    }
</script>
</html>
